// const handleTimeMoment = (time?: number) =>

import ColoredText from '@/components/ColoredText';
import FreeTimes from '@/pages/ChargeRule/components/FreeTimes';
import { CalcType, ChargeRuleTableItem } from '@/pages/ChargeRule/types.d';
import { VehicleTypeEnum } from '@/pages/Parking/Records/types.d';
import { mapChargeRule } from '@/utils/mapChargeRule';

//   moment.unix(time !== undefined ? (time - 480) * 60 : 0).format('HH:mm');

export default (props: { chargeRule: ChargeRuleTableItem; carType: VehicleTypeEnum }) => {
  const { chargeRule, carType } = props;
  const { commonLarge } = chargeRule || {};
  const isLarge =
    carType == VehicleTypeEnum.COMMON_LARGE || carType == VehicleTypeEnum.NEW_ENERGY_LARGE;
  const commonSmall = mapChargeRule(chargeRule);
  const ruleObj = isLarge ? commonLarge || commonSmall : commonSmall;
  return chargeRule ? (
    <>
      <h4>{chargeRule.name}</h4>
      <div>
        <span style={{ marginRight: '15px' }}>当前车型: {isLarge ? '大型车' : '小型车'}</span>
        <span style={{ marginRight: '15px' }}>
          时间模式：{chargeRule.calcType === CalcType.hour24 ? '24小时制' : '日期制'}
        </span>
        <span>ETC：{((chargeRule.mode || 0) & 0b01) === 1 ? '开启' : '未开启'}</span>
      </div>
      <div>
        单次免费时长：
        <ColoredText text={ruleObj.freeMin} /> 分钟
      </div>
      <div>
        每日免费时段: <FreeTimes times={ruleObj.freeTimes} />
      </div>
      超出免费时长后:
      <ul
        style={{
          listStyleType: 'none',
          fontFamily: 'monospace',
          color: '#444',
          marginBottom: '5px',
        }}
      >
        {/* <li>
          首小时：
          <ColoredText text={(firstHour / 100).toFixed(2)} /> 元
        </li> */}
        {ruleObj.chargeFrames?.map((item) => (
          <li key={item.start}>
            第{item.start}小时开始 至 第{item.end}小时结束：每{item.unit == 30 ? '半' : ''}
            小时追收&nbsp;
            <ColoredText text={(item.price / 100).toFixed(2)} /> 元；不足
            {item.unit == 30 ? '半' : '一'}小时按{item.unit == 30 ? '半' : '一'}小时计算
          </li>
        ))}
        <li>
          单日费用(每日免费时段外的总费用)达到{' '}
          <ColoredText text={(ruleObj.dayMax / 100).toFixed(2)} /> 元后，当日费用不再增加
        </li>
      </ul>
      <span>
        支付后 <ColoredText text={5} /> 分钟内驶出，不再追收额外费用
      </span>
    </>
  ) : (
    <>未获取到对应收费规则</>
  );
};
